Regexp question

Must be a dumb error, but I can't see it:

The attribute "Paragraph Style" will contain a value such as "<Object Text:Normal>" or "<Object Text:List Bullet>".

I want to extract the "Normal" or "List Bullet" part of the string, but the following is not working and prints the full text in the attribute:

Object o=current
string attrVal=o."Paragraph Style"
Regexp otStyle=regexp2 "<Object Text:[.*]>"
if (otStyle attrVal)
{
    print attrVal[match 1]
}
else
{
        print attrVal
}

Any pointers on how to fix it?


strathglass - Mon Jun 02 08:42:34 EDT 2014

Re: Regexp question
a_vestlin - Mon Jun 02 09:47:38 EDT 2014

Hi

Use normal parenthesis instead:

Regexp rxp = regexp2("<Object Text:(.*)>")

/Anders

Re: Regexp question
7XUT_Antonio_Norkus - Mon Jun 02 11:37:48 EDT 2014

It's also worth noting that the regexp will not match past any newlines in the string.

Therefore, it is best to process each line in the string, and then see if you get a match, otherwise you will only get a match if the 1st line in the string matches:

Object o = current
string attrVal = o."Paragraph Style"
Regexp aLine = regexp2 ".*"
Regexp otStyle = regexp2 "<Object Text:(.*)>"
while(aLine(attrVal) && (attrVal != ""))
{
 string thisVal = attrVal[match 0] // grab a line
 attrVal = attrVal[((end 0)+2):] // move past the newline
 if (otStyle(thisVal))
 {
  print thisVal[match 1]
 }
}

Re: Regexp question
strathglass - Mon Jun 02 12:09:06 EDT 2014

a_vestlin - Mon Jun 02 09:47:38 EDT 2014

Hi

Use normal parenthesis instead:

Regexp rxp = regexp2("<Object Text:(.*)>")

/Anders

That, unfortunately, makes no difference, FYI (I wouldn't have expected it to either).

 

Re: Regexp question
strathglass - Mon Jun 02 12:10:05 EDT 2014

7XUT_Antonio_Norkus - Mon Jun 02 11:37:48 EDT 2014

It's also worth noting that the regexp will not match past any newlines in the string.

Therefore, it is best to process each line in the string, and then see if you get a match, otherwise you will only get a match if the 1st line in the string matches:

Object o = current
string attrVal = o."Paragraph Style"
Regexp aLine = regexp2 ".*"
Regexp otStyle = regexp2 "<Object Text:(.*)>"
while(aLine(attrVal) && (attrVal != ""))
{
 string thisVal = attrVal[match 0] // grab a line
 attrVal = attrVal[((end 0)+2):] // move past the newline
 if (otStyle(thisVal))
 {
  print thisVal[match 1]
 }
}

Thanks. I am familiar with this issue, however in my case the attribute will be just one line so I don't need to worry about the +2 trick to get follow-on lines.

Re: Regexp question
GregM_dxler - Mon Jun 02 12:41:28 EDT 2014

Hi,

Use parenthesis to break out each section.

Regexp otStyle=regexp2 "(<Object Text:)(.*)(>)"

and then use match 2

Greg

Re: Regexp question
strathglass - Mon Jun 02 14:11:38 EDT 2014

GregM_dxler - Mon Jun 02 12:41:28 EDT 2014

Hi,

Use parenthesis to break out each section.

Regexp otStyle=regexp2 "(<Object Text:)(.*)(>)"

and then use match 2

Greg

OK, thanks ... now I realize my dumb mistake: I was using square brackets where I wanted round brackets!  :)

Knew it would be something simple, thanks for the help in finding it.